package com.ihisomp.controller;

import com.ihisomp.base.Result;
import com.ihisomp.dto.SysCityDto;
import com.ihisomp.service.ISysCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 省市县信息 前端控制器
 * </p>
 *
 * @author zy
 * @since 2022-01-12
 */
@RestController
@Api(value = "省市县信息", tags = "省市县信息")
@RequestMapping("/sysCity")
public class SysCityController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private ISysCityService sysCityService;

    /**
     * 新增数据
     *
     * @param sysCityDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增数据")
    @ApiImplicitParam(name = "sysCityDto", value = "省市县数据类", required = true)
    public Result add(@RequestBody SysCityDto sysCityDto) {
        logger.info("新增数据：sysCityDto={}", sysCityDto);
        Result result = sysCityService.add(sysCityDto);
        return result;
    }

    /**
     * 删除数据
     *
     * @param cityKey
     * @return
     */
    @GetMapping("/delete/{cityKey}")
    @ApiOperation("删除数据")
    @ApiImplicitParam(name = "cityKey", value = "省市县主键", required = true)
    public Result delete(@PathVariable("cityKey") String cityKey) {
        logger.info("删除数据：cityKey={}", cityKey);
        Result result = sysCityService.delete(cityKey);
        return result;
    }

    /**
     * 更新数据
     *
     * @param cityKey
     * @param sysCityDto
     * @return
     */
    @PostMapping("/update/{cityKey}")
    @ApiOperation("更新数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityKey", value = "省市县主键", required = true),
            @ApiImplicitParam(name = "sysCityDto", value = "省市县数据类", required = true)})
    public Result update(@PathVariable("cityKey") String cityKey, @RequestBody SysCityDto sysCityDto) {
        logger.info("更新数据：cityKey={}， sysCityDto={}", cityKey, sysCityDto);
        Result result = sysCityService.update(cityKey, sysCityDto);
        return result;
    }

    /**
     * 查询数据
     *
     * @param cityKey
     * @return
     */
    @GetMapping("/get/{cityKey}")
    @ApiOperation("查询数据")
    @ApiImplicitParam(name = "cityKey", value = "省市县主键", required = true)
    public Result get(@PathVariable("cityKey") String cityKey) {
        logger.info("查询数据：cityKey={}", cityKey);
        Result result = sysCityService.get(cityKey);
        return result;
    }

    /**
     * 分页查询
     *
     * @param page
     * @param size
     * @param sysCityDto
     * @return
     */
    @PostMapping("/search/{page}/{size}")
    @ApiOperation("分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true),
            @ApiImplicitParam(name = "sysCityDto", value = "省市县数据类", required = true)})
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false) SysCityDto sysCityDto) {
        logger.info("分页查询：page={}， size={}, sysCityDto={}", page, page, sysCityDto);
        Result result = sysCityService.search(page, size, sysCityDto);
        return result;
    }

    /**
     * 省市县列表
     *
     * @param sysCityDto
     * @return
     */
    @PostMapping("/selectList")
    @ApiOperation("省市县数据列表")
    @ApiImplicitParam(name = "sysCityDto", value = "省市县数据类", required = true)
    public Result selectList(@RequestBody(required = false) SysCityDto sysCityDto) {
        logger.info("省市县列表：sysCityDto={}", sysCityDto);
        Result result = sysCityService.selectDataList(sysCityDto);
        return result;
    }
}
